﻿using System;
using UnityEngine;

namespace UFrame
{
    /// <summary>
    /// 定时回调,比如fx播放一段时间,需要处理一些东西
    /// </summary>
    public class OUTimeCall : MonoBehaviour
    {
        public float time = 4f;
        private float counter = 0f;
        public string arg;
        public Action<string> onCall;
        public bool isLoop;
        private bool isActive = true;
        
        public void Update()
        {
            if (isActive)
            {
                Counter();
            }
        }

        public void Counter()
        {
            //var time =  Time.deltaTime;
            counter += Time.deltaTime;
            if (counter >= time)
            {
                onCall?.Invoke(arg);
                if (!isLoop)
                {
                    isActive = false;
                }
            }
        }

    }
}